<template>
  <div class="programDetail">
    <h3 class="dialog-plate-title">工艺详情</h3>
    <div class="detail width96">
      <el-collapse v-model="activeNames">
        <el-collapse-item name="1" >
          <template slot="title"><h4 class="plate-title">{{programObj.data.nameName+'工序详情'}}</h4></template>
          <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工序内容：</div></el-col>
              <el-col :span="18"><div v-html="programObj.data.content"></div></el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工序操作者：</div></el-col>
              <el-col :span="18"><div v-html="programObj.data.content">{{programObj.data.personName}}</div></el-col>
            </el-col>
          </el-row>
          <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工时估工：</div></el-col>
              <el-col :span="18"><div >{{programObj.data.predictWorkTime}}</div></el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工时固定：</div></el-col>
              <el-col :span="18"><div >{{programObj.data.confirmWorkTime}}</div></el-col>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item name="2">
          <template slot="title"><h4 class="plate-title">首检工序详情</h4></template>
          <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工序内容：</div></el-col>
              <el-col :span="18"><div v-html="programObj.data.checkContent"></div></el-col>
            </el-col>
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工序操作者：</div></el-col>
              <el-col :span="18"><div >{{programObj.data.checkPersonName}}</div></el-col>
            </el-col>
          </el-row>
          <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工时估工：</div></el-col>
              <el-col :span="18"><div>{{programObj.data.checkPredictWorkTime}}</div></el-col>  
            </el-col>
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工时固定：</div></el-col>
              <el-col :span="18"><div>{{programObj.data.checkConfirmWorkTime}}</div></el-col>  
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item  name="3">
          <template slot="title"><h4 class="plate-title">次检工序详情</h4></template>
          <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工序内容：</div></el-col>
              <el-col :span="18"><div v-html="programObj.data.cjCheckContent"></div></el-col>  
            </el-col>
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工序操作者：</div></el-col>
              <el-col :span="18"><div>{{programObj.data.cjCheckPersonName}}</div></el-col>  
            </el-col>
          </el-row>
          <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工时估工：</div></el-col>
              <el-col :span="18"><div>{{programObj.data.cjCheckPredictWorkTime}}</div></el-col> 
            </el-col>
            <el-col :span="12">
              <el-col :span="6"><div class="detail-title">工时固定：</div></el-col>
              <el-col :span="18"><div>{{programObj.data.cjCheckConfirmWorkTime}}</div></el-col>   
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item  name="4">
          <template slot="title"><h4 class="plate-title">工艺上传</h4></template>
            <div>
              <uploadList :upLoadType="programObj.data.name" :drawNo="programObj.drawCode" :processId="programObj.data.id" ref="processUploadRef"></uploadList>
            </div>
        </el-collapse-item>
        <el-collapse-item  name="5">
          <template slot="title"><h4 class="plate-title">工装</h4></template>
            <el-table :data="gztableData"  style="width: 100%; margin:0 auto;">
              <el-table-column prop="wkgz" label="规格"></el-table-column>
              <el-table-column prop="wkgzCount" label="数量"></el-table-column>
            </el-table> 
        </el-collapse-item>
        <el-collapse-item  name="6">
          <template slot="title"><h4 class="plate-title">量具</h4></template>
            <el-table :data="ljtableData"  style="width: 100%; margin:0 auto;">
              <el-table-column prop="wklj" label="规格"></el-table-column>
              <el-table-column prop="wkljCount" label="数量"></el-table-column>
            </el-table>
        </el-collapse-item>
      </el-collapse>
    </div>
    <h3 class="dialog-plate-title">编程程序
      <el-button type="primary" icon="el-icon-plus" round @click="addProcessFace('insert')" v-if="status!=='watch'">新增</el-button>
      <el-button type="danger" icon="el-icon-delete" round @click="addProcessFace('delete')" v-if="status!=='watch'">删除</el-button>
      <el-button type="danger" icon="el-icon-print" round @click="printProcessFace" v-if="status!=='watch'">打印</el-button>
    </h3>
    <div v-if="programList.length>0" >
      <div class="tabHeader">
        <div class="tabHeader-item" v-for="item in programList" :key="item.id" :class="{'active':activeRow.processFace===item.processFace}" @click="changeRow(item)">{{item.processFaceAlias? item.processFaceAlias:item.processFaceName}}</div>
      </div>
      <div>
        <h4 class="plate-title">{{activeRow.processFaceAlias?activeRow.processFaceAlias:activeRow.processFaceName}}面详情</h4>
        <div  v-loading="loading">
        <el-form :model="activeRow" ref="ruleForm1" label-width="120px" class="demo-ruleForm" :inline="true">
          <el-form-item label="加工面" prop="processFace">
            <el-select v-model="activeRow.processFace" placeholder="请选择" class="width220" disabled>
              <el-option v-for="item in processFaceList" :key="item.code" :label="item.name" :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="加工面别名" prop="processFaceAlias">
             <el-input v-model="activeRow.processFaceAlias" class="width220" :disabled="disableEdit"></el-input>
          </el-form-item>
          
          <el-form-item label="适合设备" prop="machine">
            <!-- <el-autocomplete class="width220" multiple v-model="activeRow.machine.name" v-if="activeRow.machine" :fetch-suggestions="querySearch" placeholder="请输入内容" @select="handleSelect" :disabled="disableEdit"></el-autocomplete> -->
            <el-select v-model="activeRow.machine.name" multiple collapse-tags placeholder="请选择适用设备" class="width220" >
              <el-option v-for="item in machineAllList" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="装夹方式" prop="installType">
            <el-select v-model="activeRow.installType" placeholder="请选择" class="width220" :disabled="disableEdit">
              <el-option v-for="item in installTypeList" :key="item.code" :label="item.name" :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="首次装夹时间" prop="fristInstall">
            <el-input v-model="activeRow.fristInstall" class="width220" :disabled="disableEdit">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
          <el-form-item label="装夹时间" prop="install">
            <el-input v-model="activeRow.install" class="width220" :disabled="disableEdit">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
          	<el-form-item label="数铣指定设备" prop="secondMac">
            <el-select v-model="activeRow.secondMac" placeholder="请选择" class="width220" :disabled="disableEdit">
              <el-option v-for="item in secondMacList" :key="item.code" :label="item.name" :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="运行时间" prop="runTime">
            <el-input v-model="activeRow.runTime" class="width220" :disabled="disableEdit">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
          <el-form-item label="首次检验时间" prop="fristCheck">
            <el-input v-model="activeRow.fristCheck" class="width220" :disabled="disableEdit">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
          <el-form-item label="填写人" prop="creatorName">
            <el-input v-model="activeRow.creatorName" disabled class="width220"></el-input>
          </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
            <el-input v-model="activeRow.createTime" disabled class="width220"></el-input>
          </el-form-item>
          <el-form-item label="图纸" prop="path" v-if="disableEdit" class="heightAuto" >
            <el-image  style="width: 178px; height: 178px" :src="activeRow.path"  :preview-src-list="activeRow.imageArray"></el-image>
          </el-form-item>
          <el-form-item label="图纸上传" prop="path" class="heightAuto"  v-else>
            <el-upload class="avatar-uploader" :action="actionUrl" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload"> 
              <img v-if="activeRow.path" :src="activeRow.path"  class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="技术要求" prop="techReq" class="heightAuto form-item-block" >
           <quill-editor v-model="activeRow.techReq" :disabled="disableEdit" :options="editorOption" class="width520"></quill-editor>
          </el-form-item>
          <el-form-item  class="form-item-block text-center" v-if="status!=='watch'">
            <el-button type="primary" @click="onSubmit('edit')"  v-if="disableEdit">编辑</el-button>
            <el-button type="primary" @click="onSubmit('ruleForm1','update')" v-else>提交</el-button>
          </el-form-item>
        </el-form>
        </div>
      </div>
      <el-popover
        ref="djpopover"
        placement="right"
        title="刀具库"
      
        trigger="click"
        >
        <el-form :inline="true" :model="search">
              <el-form-item label="直径" >
                  <el-input style="width:100px;" v-model="search.diameter" focus clearable></el-input>
              </el-form-item>
              <el-form-item label="深度" >
                  <el-input  style="width:100px;" v-model="search.depth" clearable></el-input>
              </el-form-item>
              <el-form-item label="刃长" >
                  <el-input  style="width:100px;" v-model="search.blade" clearable></el-input>
              </el-form-item>
              <el-form-item label="磨" >
                  <el-input  style="width:100px;" v-model="search.mo" clearable></el-input>
              </el-form-item>
              <el-button type="primary" @click="searchDjList">查询</el-button>
              <el-button type="primary" @click="resSearchDjList">重置</el-button>
        </el-form>
        <!-- <el-table :data="wkdjList"  @selection-change="handleSelectionChanges" ref="wkdjTable"> -->
        <el-table :data="wkdjList" @row-click="submitDjRow" @selection-change="handleSelectionChanges" ref="wkdjTable">
              <!-- <el-table-column type="selection"  width="55"></el-table-column> -->
              <!-- <el-table-column prop="planTaskDetail.processFaceName" label="面" sortable width="80"></el-table-column> -->
              <el-table-column prop="name" label="名称" sortable width="80"></el-table-column>
              <el-table-column prop="diameter" label="直径" sortable min-width="80"></el-table-column>
              <el-table-column prop="depth" label="深度" sortable min-width="80"></el-table-column>
              <el-table-column prop="blade" label="刃长" sortable min-width="80" ></el-table-column>
              <el-table-column prop="mo" label="磨" sortable min-width="100"></el-table-column>
              <el-table-column prop="creatorName" label="创建人" sortable width="100"></el-table-column>
              <el-table-column prop="createTime" label="创建时间" sortable min-width="160"></el-table-column>
        </el-table>
        <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
        <div style="margin-top: 20px">
          <el-button @click="submitDj">确定</el-button>
        </div>
      </el-popover>
      <!-- 编程刀列表 -->
      <h4 class="plate-title">{{activeRow.processFaceAlias? activeRow.processFaceAlias:activeRow.processFaceName}}面刀
        <el-button type="primary" @click="showDialog2('insert')" v-if="status!=='watch'">新增</el-button>
        <!-- <el-button type="success" @click="showDialog2('copy')" v-if="status!=='watch'">复制</el-button> -->
        <!-- <el-button type="success" v-popover:djpopover v-if="status!=='watch'">选取</el-button> -->
        <!-- <el-select v-model="wkdj" @change="sysVal" filterable clearable placeholder="请选择" >
                    <el-option
                      v-for="item in wkdjList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id">
                    </el-option>
        </el-select>  -->
      </h4>
      <div class="width96">
        <el-table :data="activeRow.cutterList" stripe border class="user-table" style="width: 100%;">
            <el-table-column type="index" label="序号" ></el-table-column>
            <el-table-column prop="name" label="名称" sortable width="80">
              <template slot-scope="scope" >
                <div>
                  <div v-if="cutterEditDisable">{{scope.row.name}}</div>
                  <el-input v-model="scope.row.name" :disabled="cutterEditDisable" v-else class="inputPadding4"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="diameter" label="直径" sortable min-width="80">
              <template slot-scope="scope" >
                <div>
                  <div v-if="cutterEditDisable">{{scope.row.diameter}}</div>
                  <el-input v-model="scope.row.diameter"  :disabled="cutterEditDisable"  v-else class="inputPadding4"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="depth" label="深度" sortable min-width="80">
              <template slot-scope="scope" >
                <div>
                  <div v-if="cutterEditDisable">{{scope.row.depth}}</div>
                  <el-input v-model="scope.row.depth" :disabled="cutterEditDisable"  v-else class="inputPadding4"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="blade" label="刃长" sortable min-width="80" >
              <template slot-scope="scope" >
                <div>
                  <div v-if="cutterEditDisable">{{scope.row.blade}}</div>
                  <el-input v-model="scope.row.blade"  :disabled="cutterEditDisable"  v-else class="inputPadding4"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="mo" label="磨" sortable min-width="100">
              <template slot-scope="scope" >
                <div>
                  <div v-if="cutterEditDisable">{{scope.row.mo}}</div>
                  <el-input v-model="scope.row.mo" :disabled="cutterEditDisable"  v-else class="inputPadding4"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注" sortable min-width="140">
              <template slot-scope="scope" >
                <div>
                  <div v-if="cutterEditDisable">{{scope.row.remark}}</div>
                  <el-input v-model="scope.row.remark" :disabled="cutterEditDisable"  v-else class="inputPadding4"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="creatorName" label="创建人" sortable width="100"></el-table-column>
            <el-table-column prop="createTime" label="创建时间" sortable min-width="160">
              <template slot-scope="scope">
                {{timestampToTime(scope.row.createTime,'yyyy-mm-dd hh:mm:ss')}}
              </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" align="right" min-width="60">
              <template slot-scope="scope">

                <el-button @click="changeCutterEditDisable" type="text" size="small" v-if="cutterEditDisable">
                   <el-link type="danger">编辑</el-link>
                </el-button>

                <el-button @click="editAllCutter" type="text" size="small" v-else>
                   <el-link type="danger">确认</el-link>
                </el-button>

                <el-button @click="showDialog2('delete',scope.row)" type="text" size="small" v-if="status!=='watch'">
                   <el-link type="danger">删除</el-link>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- <el-button type="primary" @click="changeCutterEditDisable" v-if="cutterEditDisable">编辑</el-button>
          <el-button type="primary" @click="editAllCutter" v-else>确认</el-button> -->
      </div>
        <!-- 编程程序上传 -->
      <h4 class="plate-title">{{activeRow.processFaceAlias? activeRow.processFaceAlias:activeRow.processFaceName}}面编程程序上传</h4>
      <div class="width96">
        <div v-if="status!=='watch'">
        <uploadtemp  :taskTotalId="taskTotalId" :isProcessType="1" :upLoadType="activeRow.processFace" :drawNo="programObj.drawCode" :processId="programObj.processId" @insert-success="handleAvatarSuccess1"></uploadtemp>  
        </div> 
        <uploadList  :upLoadType="activeRow.processFace" :drawNo="programObj.drawCode" :processId="programObj.processId" ref="uploadListRef"></uploadList>
      </div>
    </div>
    <div v-else class="noData">
      <div class="el-icon-folder-opened"></div>
      <div>暂无编程程序，请新增</div>
    </div>

    <!-- 新增/编辑刀 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog2.title" :visible.sync="dialog2.isShow" v-dialogDrag :append-to-body="true" @closed="closedHandle">
      <div v-if="dialog2.type==='insert' ">
        <el-form :model="dialog2.formData"  ref="ruleForm2" label-width="120px" class="demo-ruleForm" :inline="true">
          <el-form-item label="数量" prop="name">
            <el-input-number v-model="dialog2.formData.nums" :min="1"></el-input-number>
          </el-form-item>
          <el-form-item  class="form-item-block text-center">
            <el-button type="primary" @click="onSubmit('ruleForm2')">确认</el-button>
          </el-form-item>
        </el-form>
      </div> 
      <!-- <div v-else-if="dialog2.type==='update'"> -->
       <!-- <div v-if="dialog2.type==='update' || dialog2.type==='insert'">
        <el-form :model="dialog2.formData"  ref="ruleForm2" label-width="120px" class="demo-ruleForm" :inline="true">
          <el-form-item label="名称" prop="name">
            <el-input v-model="dialog2.formData.name" class="width220" :disabled="status==='watch'"></el-input>
          </el-form-item>
          <el-form-item label="直径" prop="diameter">
            <el-autocomplete  class="width220" v-model="dialog2.formData.diameter" :fetch-suggestions="querySearchAsync" placeholder="请输入直径" @select="handleSelect" :disabled="status==='watch'"></el-autocomplete>
          </el-form-item>
          <el-form-item label="深度" prop="depth">
            <el-input v-model="dialog2.formData.depth" class="width220" :disabled="status==='watch'">
            </el-input>
          </el-form-item>
          <el-form-item label="刃长" prop="blade">
            <el-input v-model="dialog2.formData.blade" class="width220" :disabled="status==='watch'">
            </el-input>
          </el-form-item>
          <el-form-item label="磨" prop="mo">
            <el-input v-model="dialog2.formData.mo" class="width220" :disabled="status==='watch'">
            </el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="dialog2.formData.remark" class="width220" :disabled="status==='watch'" type="textarea">
            </el-input>
          </el-form-item>
          <el-form-item label="创建人" prop="creatorName" v-if="dialog2.type==='update'">
            <el-input v-model="dialog2.formData.creatorName" disabled class="width220"></el-input>
          </el-form-item>
          <el-form-item label="创建时间" prop="createTime" v-if="dialog2.type==='update'">
            <el-input v-model="dialog2.formData.createTime" disabled class="width220"></el-input>
          </el-form-item>
          <el-form-item  class="form-item-block text-center" v-if="status!=='watch'">
            <el-button type="primary" @click="onSubmit('ruleForm2')">确认</el-button>
          </el-form-item>
        </el-form>
       </div> -->
       <div v-else>
         <div v-for=" item in allProgramCutterList" :key="item.name">
            <h3 class="dialog-plate-title">{{item.name}}面</h3>
            <el-table :data="item.list" stripe border class="user-table" style="width: 100%;" @selection-change="handleSelectionChange($event,item.name)">
              <el-table-column fixed type="index" label="*" sortable min-width="30" ></el-table-column>
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="planTaskDetail.processFaceName" label="面" sortable width="80"></el-table-column>
              <el-table-column prop="name" label="刀号" sortable width="80"></el-table-column>
              <el-table-column prop="diameter" label="直径" sortable min-width="80"></el-table-column>
              <el-table-column prop="depth" label="深度" sortable min-width="80"></el-table-column>
              <el-table-column prop="blade" label="刃长" sortable min-width="80" ></el-table-column>
              <el-table-column prop="mo" label="磨" sortable min-width="100"></el-table-column>
              <el-table-column prop="creatorName" label="创建人" sortable width="100"></el-table-column>
              <el-table-column prop="createTime" label="创建时间" sortable min-width="160"></el-table-column>
              <!-- <el-table-column label="操作">
                  <template slot-scope="scope">
                      <el-button type="text" @click="deleteRow(scope.row)">删除</el-button>
                  </template>
                </el-table-column> -->
            </el-table>
        </div>
        <div class="text-center marginT24">
            <el-button type="success" @click="copyClick">复制选择的刀</el-button>
        </div>        
      </div>
    </el-dialog>
    <div style="display:none">
        <!--  -->
        <processFaceCard  ref="processFaceCardRef" :pdfType="pdfType"></processFaceCard>
    </div>
  </div>
</template>
<script>
import planApi from 'plugins/axios/planApi.js';
import materielApi from 'plugins/axios/materielApi.js';
import baseApi from 'plugins/axios/baseApi.js';
import processFaceCard from 'views/components/processFaceCard.vue' /**工艺流程卡 */ 

import uploadtemp from 'views/components/uploadtemp.vue' /**大文件上传 */
import uploadList from 'views/components/uploadList.vue' /**1-图纸上传、2-工艺上传、3-图形文件上传 的列表组件 */
import { quillEditor } from 'vue-quill-editor' // 调用富文本编辑器
import 'quill/dist/quill.snow.css' // 富文本编辑器外部引用样式  三种样式三选一引入即可
//import 'quill/dist/quill.core.css'
//import 'quill/dist/quill.bubble.css'
import * as Quill from 'quill'; // 富文本基于quill
export default {
  name: 'tableList29',
   components: {
    uploadtemp,
    uploadList,
    quillEditor,
    processFaceCard,
  },
  props:{
    programObj:{
      type:Object
    },
    status:{
      type:String
    },
    taskTotalId:{
      type:[Number,String]
    },
  },
  data (){
    return {
      search:{
          diameter:'',
          depth:'',
          blade:'',
          mo:'',
      },
      pdfType:'face',
      wkdj:'',
      editorOption:{/**富文本编辑器配置 */
        modules: {
          toolbar: [
            [{ 'size': ['small', false, 'large'] }],
            ['bold', 'italic']
          ],
          history: {
            delay: 1000,
            maxStack: 50,
            userOnly: false
          }
        }
      },
      processProductionList:[],
      wkdjList:[],
      gztableData:[],
      ljtableData:[],
      loading:false,
      disableEdit:true,
      isLastRow:false,
      activeRow:{cutterList:[]},
      pdfActionUrl:baseApi.drawInfoUpload(),
      actionUrl:baseApi.imageUpload(),
      programList:[],
      processFaceList:[],/**工序面列表 */
      activeNames:'1',
      dialog2:{
        title:'',
        isShow:false,
        type:'',
        formData:{}
      },
      currentPage:1,
      pageSize:10,
      total:0,
      pdfData:{},
      machineAllList:[],/**机器列表 */
      cutterList:[],/**刀列表 */
      cutterEditDisable:true,/**编辑刀列表 */
      diameterAllList:[],/**刀具所有直径列表 */
      installTypeList:[],/***装夹方式列表 */
      secondMacList:[],/**数铣指定设备列表 */
      allProgramCutterList:[],/**所有面的刀列表 */
      multipleSelection:{},/**选择了哪些刀 */
      multipleSelections:[],
    }
  },
  watch:{
    
  },
  mounted(){
    let self = this;
    self.$refs.processUploadRef.getTableList();
    baseApi.getCodeList(7).then(res=>{
       res.content.forEach(item=>{
         item.value = item.name;
       })
      self.diameterAllList= res.content;
    })
    baseApi.getCodeList(8).then(res=>{
       res.content.forEach(item=>{
        item.code = Number(item.code);
      })
      self.installTypeList= res.content;
    })
    baseApi.getCodeList(9).then(res=>{
      res.content.forEach(item=>{
        item.code = Number(item.code);
      })
      self.secondMacList= res.content;
    })
    
    
  },
  created(){
    this.getProcessFaceList();
    this.getMachineAllList();
    this.queryWkdjList();
  },
  methods:{
      handleSizeChange(val){
            let self = this;
            self.pageSize = val;
            this.queryWkdjList();
      },
      handleCurrentChange(val){
            let self = this;
            self.currentPage = val;
          this.queryWkdjList();
        },
    searchDjList(){
      let self = this;
      self.queryWkdjList();
    },
    resSearchDjList(){
      let self = this;
      self.search={
          diameter:'',
          depth:'',
          blade:'',
          mo:'',
      };
      self.queryWkdjList();
    },
    deleteRow(row){
      let self = this;
      let param = {
        idx:row.idx,
        id:this.activeRow.id,
        cutId:row.id,
      }
      planApi.deleteRow(param).then(res=>{
            if(res.content!=null && res.content!=undefined ){
              let item  =  res.content;
              // item.imageArray=[];
              // item.imageArray.push(item.path);
              // item.machine = item.machine?item.machine:{name:''}
              //        item.machine.name= [];
              //      if(item.fitMacs!=null&&item.fitMacs.length>0){
              //         item.fitMacs.forEach(itemm=>{
              //           item.machine.name.push(itemm.id);
              //           });
              //      }else{
  
              //      }
            self.activeRow.cutterList = item.cutterList;
            }        
      });
    },
    submitDj(){
      let self = this;
      let cutters =[];
      if(self.multipleSelections!=null &&　self.multipleSelections!= undefined && self.multipleSelections.length>0){
        
        self.multipleSelections.forEach(item=>{
            cutters.push(item.id);
        })
      }
      let param = {
        id:self.activeRow.id,
        cutters:cutters.join(','),
      }
      planApi.insertDj(param).then(res=>{
          self.$refs.wkdjTable.clearSelection();
          if(res.content!=null && res.content!=undefined ){
            let item  =  res.content;
            item.imageArray=[];
            item.imageArray.push(item.path);
            item.machine = item.machine?item.machine:{name:''}
                   item.machine.name= [];
                 if(item.fitMacs!=null&&item.fitMacs.length>0){
                    item.fitMacs.forEach(itemm=>{
                      item.machine.name.push(itemm.id);
                      });
                 }else{

                 }
          self.activeRow = item;
          }
          //self.getPlanTaskCutterList();
      });
    },
    submitDjRow(row){
      let self = this;
      let cutters =[];
      cutters.push(row.id);
      let diameter =row.diameter;
      let depth =row.depth;
      let blade =row.blade;
      let mo =row.mo;
      let isActive = true;
      // self.activeRow.cutterList.forEach(element => {
      //   if(element.diameter===diameter &&element.depth ===depth && element.blade === blade && element.mo === mo  ){
      //     self.$message({
      //       message:"已存在相同刀具",
      //       type:"success"
      //     });
      //     isActive = false;
      //     return;
      //   }
      // });
      // if(self.multipleSelections!=null &&　self.multipleSelections!= undefined && self.multipleSelections.length>0){
        
      //   self.multipleSelections.forEach(item=>{
      //       cutters.push(row.id);
      //   })
      // }
      let param = {
        id:self.activeRow.id,
        cutters:cutters.join(','),
      }
      if(isActive){
        planApi.insertDj(param).then(res=>{
            // self.$refs.wkdjTable.clearSelection();
            if(res.content!=null && res.content!=undefined ){
              let item  =  res.content;
              item.imageArray=[];
              item.imageArray.push(item.path);
              item.machine = item.machine?item.machine:{name:''}
                     item.machine.name= [];
                   if(item.fitMacs!=null&&item.fitMacs.length>0){
                      item.fitMacs.forEach(itemm=>{
                        item.machine.name.push(itemm.id);
                        });
                   }else{
  
                   }
            self.activeRow = item;
            }
            //self.getPlanTaskCutterList();
        });
      }
    },
    handleSelectionChanges(val) {
        this.multipleSelections = val;
    },
    sysVal(val){
      alert(val);
    },
    queryWkdjList(){
        let self = this;
        let param = {
          groupId:1,
          currentPage:self.currentPage,
          pageSize:self.pageSize,
          diameter:self.search.diameter,
          depth:self.search.depth,
          blade:self.search.blade,
          mo:self.search.mo,
        };
        planApi.queryByCondition(param).then(res=>{
          self.wkdjList = res.content.records;
          self.total = res.content.total;
        });
    },
    groupTableData(){
      let self = this;
      if(self.processProductionList!=null && self.processProductionList != undefined && self.processProductionList.length>0){
        self.gztableData = [];
        self.ljtableData = [];
        self.processProductionList.forEach(element => {
          if(element.groupId==2){
             self.gztableData.push({wkgz:element.production.name,wkgzCount:element.count})
          }else if(element.groupId==3){
             self.ljtableData.push({wklj:element.production.name,wkljCount:element.count})
          }
        });
      }
    },
    getProcessFaceList(){
      let self = this;
      baseApi.getCodeList(2).then(res=>{
        self.processFaceList = res.content;
      })
    },
    getGzAndLjInfo(){
      //获取工装和量具的信息
      let self = this;
      planApi.getGzAndLjInfo(self.programObj.tid).then(res=>{
        self.processProductionList =  res.content;
        self.groupTableData();
      });
    },
    getProgramList(){
      let self = this;
      self.getGzAndLjInfo();

      materielApi.planTaskDetailList(self.programObj.tid).then(res=>{
        if( res.content.length>0){
          res.content.forEach(item=>{
            item.imageArray=[];
            item.imageArray.push(item.path);
            item.machine = item.machine?item.machine:{name:''}
                   item.machine.name= [];
                 if(item.fitMacs.length>0){
                    item.fitMacs.forEach(itemm=>{
                      item.machine.name.push(itemm.id);
                      });
                 }else{

                 }
          })
     
          self.activeRow =self.isLastRow?res.content[res.content.length-1]:res.content[0];
          self.activeRow.cutterList =self.activeRow.planTaskCutters;
          // self.getPlanTaskCutterList();
          self.pdfData.drawInfo =JSON.stringify({
            processId:self.programObj.processId,
            type:self.activeRow.processFace,
            drawNo:self.programObj.drawCode
          })
          setTimeout(()=>{
            self.$refs.uploadListRef.getTableList();
          },200)
          
        }
        self.programList = res.content;
      })
 
    },
    /**切换编程的每一面*/ 
    changeRow(row){
      this.isLastRow = false;
      this.disableEdit = true;
      this.activeRow = row;
      this.getPlanTaskCutterList()
      this.pdfData.drawInfo =JSON.stringify({
        processId:this.programObj.processId,
        type:this.activeRow.processFace,
        drawNo:this.programObj.drawCode
      })
      this.$refs.uploadListRef.getTableList();
    },
    /**新增操作面 */
    addProcessFace(type){
      let self = this;
      switch(type){
        case 'insert':
          self.$confirm('是否新增程序操作面', '提示', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning'
          }).then(() => {
            self.isLastRow = true;
            self.onSubmit('ruleForm1','insert');
          }).catch(() => {});
          break;
        case 'delete':
          self.$confirm('是否删除程序操作面', '提示', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning'
          }).then(() => {
            materielApi.deleteMian(self.programObj.tid).then(res=>{
              self.$message.success('删除成功！');
              self.getProgramList();
            })
          }).catch(() => {});
           break;
        case 'print':
          break;
      }
      
    },
    printProcessFace(){
      let self = this;
      console.log(self.programList);
      self.$refs.processFaceCardRef.getCgPdfData(self.programList);
    },
    showDialog2(type,row){
       let self = this;
      self.dialog2.type = type;
      switch(type){
        case 'insert':
          self.dialog2.isShow =true;
          self.dialog2.title ="新增刀";
          self.dialog2.formData ={};
          break;
        case 'update':
          self.dialog2.isShow =true;
          self.dialog2.title =`编辑刀${row.name}`;
          self.dialog2.formData =JSON.parse(JSON.stringify(row));
          break;
        case 'delete':
          this.$confirm(`是否删除${row.name}刀?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          materielApi.deleteCutter(row.id).then(res=>{
            self.$message.success(`${row.name}删除成功!`);
            this.getPlanTaskCutterList()
          })
        }).catch(() => {});
        break;
        case 'copy':
          self.dialog2.isShow =true;
           self.dialog2.title =`请选择需要复制的刀`;
          this.getAllProgramCutter();
          break;
      }
    },
    /**获取所有面得刀列表*/ 
    getAllProgramCutter(){
      let self = this;
      materielApi.getAllProgramCutter(self.programObj.tid).then(res=>{
        self.allProgramCutterList=[];
        for(let i in res.content){
          self.allProgramCutterList.push({
            name: i,
            list: res.content[i]
          })
        }
        console.log(self.allProgramCutterList);
      })
    },
    /**选择了哪些面 */
    handleSelectionChange(val,name){
      this.multipleSelection[name] =val;
    },
    copyClick(){
      let self = this;
      let postData = [];
      for (let i in self.multipleSelection){
        if(self.multipleSelection[i].length>0){
          self.multipleSelection[i].forEach(item=>{
          postData.push({
            faceId:self.activeRow.id,
            cutterId:item.id
          })
        })
        }
      }
      if(postData.length<1){
        self.$message.error('请至少选择至少一个要复制的刀');
        return;
      }
      materielApi.copyPlanTaskCutter(postData).then(res=>{
        self.dialog2.isShow = false;
        self.$message.success('复制刀成功！');
        self.getPlanTaskCutterList();
      })
    },
    getMachineAllList(){
      let self = this;
      baseApi.machineAllList().then(res=>{
        res.content.forEach(item=>{
        item.value=item.name;
        })
        self.machineAllList= res.content;
      })
    },
    querySearch(queryString, cb) {
        var restaurants = this.machineAllList;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
    },
    createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
    handleSelect(item) {
      this.activeRow.macId = item.id; 
    },
    onSubmit(template,type){
      let self = this;
      switch(template){
        /**新增/编辑编程面信息*/ 
        case 'ruleForm1': 
          self.loading = true;
          var postData= type==='insert'?{tid:self.programObj.tid}:{
            tid:self.activeRow.tid,
            id:self.activeRow.id,
            processFace:self.activeRow.processFace,
            processFaceAlias:self.activeRow.processFaceAlias,
            fristInstall:self.activeRow.fristInstall,
            install:self.activeRow.install,
            runTime:self.activeRow.runTime,
            fristCheck:self.activeRow.fristCheck,
            techReq:self.activeRow.techReq,
            macId:self.activeRow.macId,
            path:self.activeRow.path,
            fitMachines:self.activeRow.machine.name?self.activeRow.machine.name.join(','):'',
            installType:self.activeRow.installType,
            secondMac:self.activeRow.secondMac
          }
            let param = {
              itemType: type==='insert'?9:10,
              startTime:new Date(),
              endTime:null,
              taskTotalId:self.taskTotalId,
            }
            self.insertDzjz(param);
          materielApi.insertUpdatePlanTaskDetail(type,postData).then(res=>{
            self.loading = false;
            self.disableEdit = type==='insert'?false:true;
            self.$message.success(`${type==='insert'?'新增编程程序':'编辑编程程序'+self.activeRow.processFaceName}成功`);
            self.getProgramList();
          },error=>{
             self.loading = false;
          })
          break;
          /**新增/编辑刀信息*/ 
        /** case 'ruleForm2':
          if( self.dialog2.type==='insert'){
            let params = {
              itemType:11,
              startTime:new Date(),
              endTime:null,
              taskTotalId:self.taskTotalId
            };
            self.insertDzjz(params);
            //进行锚点开发
            // materielApi.batchAddCutter({
            //   tid:self.activeRow.id,
            //   nums:self.dialog2.formData.nums
            // }).then(res=>{
            //   self.dialog2.isShow=false;
            //   self.$message.success(`${self.dialog2.title}成功`);
            //   self.getPlanTaskCutterList();
            // })
             self.dialog2.formData.tid =  self.activeRow.id;
             self.dialog2.formData.state = 0;//资源状态   0：待采购，1：已采购
            planApi.insertCutterAndLinkCurrentFace(self.dialog2.formData).then(res=>{
              self.dialog2.isShow=false;
              self.$message.success(`${self.dialog2.title}成功`);
              self.queryWkdjList();

              if(res.content!=null && res.content!=undefined ){
                  let item  =  res.content;
                  item.imageArray=[];
                  item.imageArray.push(item.path);
                  item.machine = item.machine?item.machine:{name:''}
                        item.machine.name= [];
                      if(item.fitMacs!=null&&item.fitMacs.length>0){
                          item.fitMacs.forEach(itemm=>{
                            item.machine.name.push(itemm.id);
                            });
                      }else{

                      }
                self.activeRow = item;
                }
              // self.getPlanTaskCutterList();
            })
          }else{
            let params = {
              itemType:12,
              startTime:new Date(),
              endTime:null,
              taskTotalId:self.taskTotalId
            };
            self.insertDzjz(params);
          materielApi.insertUpdatePlanTaskCutter(self.dialog2.type,self.dialog2.formData).then(res=>{
            self.dialog2.isShow=false;
            self.$message.success(`${self.dialog2.title}成功`);
            // self.getPlanTaskCutterList();
          })
          }
          
        break; **/
          /**新增/编辑刀信息*/ 
        case 'ruleForm2':
          if( self.dialog2.type==='insert'){
            let params = {
              itemType:11,
              startTime:new Date(),
              endTime:null,
              taskTotalId:self.taskTotalId
            };
            self.insertDzjz(params);
            materielApi.batchAddCutter({
              tid:self.activeRow.id,
              nums:self.dialog2.formData.nums
            }).then(res=>{
              self.dialog2.isShow=false;
              self.$message.success(`${self.dialog2.title}成功`);
              self.getPlanTaskCutterList();
            })
          }else{
            let params = {
              itemType:12,
              startTime:new Date(),
              endTime:null,
              taskTotalId:self.taskTotalId
            };
            self.insertDzjz(params);
          materielApi.insertUpdatePlanTaskCutter(self.dialog2.type,self.dialog2.formData).then(res=>{
            self.dialog2.isShow=false;
            self.$message.success(`${self.dialog2.title}成功`);
            self.getPlanTaskCutterList();
          })
          }
          
        break;
        /**点击编辑*/
        case 'edit':
          self.disableEdit = false;
          let params = {
              itemType:10,
              startTime:new Date(),
              endTime:null,
              taskTotalId:self.taskTotalId
          };
            self.insertDzjz(params);
        break;   
      }
    },
    closedHandle(){
      this.getPlanTaskCutterList();
    },
    /**获取刀片列表*/ 
    getPlanTaskCutterList(){
      let self = this;
      materielApi.planTaskCutterList(self.activeRow.id).then(res=>{
        self.activeRow.cutterList = res.content;
      })
    },
    beforeAvatarUpload(file){
      const isImage = /.(gif|jpg|jpeg|png|gif|jpg|png)$/.test(file.type);
      if (!isImage) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
      }
        return isImage;
    },
    beforeAvatarUpload1(file){/**文件上传前格式和大小的验证*/
      console.log(file);
      return true;
    },
    handleAvatarSuccess(res, file){
      this.activeRow.path = res.content;
    },
    handleAvatarSuccess1(response, file, fileList){
     this.$refs.uploadListRef.getTableList();
    },
    querySearchAsync(queryString, callback){
      var restaurants = this.diameterAllList;
      var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
      callback(results);
    },
    /***改变刀列表的状态 */
    changeCutterEditDisable(){
      this.cutterEditDisable= false
    },
    /***点击提交刀列表 */
    editAllCutter(){
      let self  = this;
      materielApi.updateAllCutter(self.activeRow.cutterList).then(res=>{
        self.cutterEditDisable= true;
        self.getPlanTaskCutterList();
        self.$message.success('编辑成功')
      })
    },
    /**员工工时统筹 */
    insertDzjz(param){
      let self = this;
      // let param={
      //   itemType:self.workTime.itemType,
      //   startTime:self.workTime.startTime,
      //   endTime:self.workTime.endTime,
      //   taskTotalId:self.workTime.taskTotalId,
      // };
      planApi.insertDzjz(param).then(res=>{
        console.log(res.content);
      });
    },
  }
}
</script>
<style lang="stylus" scoped>
h4.plate-title
  color $auxiliary-color3
  border-left: 4px solid $auxiliary-color1;
  padding-left 8px
  line-height 24px
  font-size 15px
  margin 12px auto
  margin-left 8px
  
.programDetail
  width 100%
.width96
  width 96%
  margin auto
  .detail
    border-left 1px solid #EBEEF5
    border-right 1px solid #EBEEF5
  .detail-title
    font-weight bold
    font-size 14px
    text-align right
  .row-bg
    margin-top 8px
.tabHeader
  width 100%
  overflow hidden
  line-height 40px
  font-size 14px
  border-bottom 1px solid #dedede
  .tabHeader-item
    padding 0 20px
    height 40px
    box-sizing border-box
    line-height 40px
    display inline-block
    list-style none
    font-size 14px
    font-weight 500
    color #303133
    position  relative
    margin-bottom -1px
  .active
    border-bottom 2px solid $theme-color
.tabContent
  margin-top 24px
.noData
  text-align center
  font-size 16px
  margin-top 44px
  color #C0C4CC
  padding-bottom 24px
  .el-icon-folder-opened
    font-size 44px
    margin-bottom 10px
</style>